<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="https://www.baidu.com"  id="regedit"  method="POST"  autocomplete="off" >

    <input  type="text"  id="username"  name="username"  placeholder="Username..."  >

    <input  type="password"  id="password" name="password" placeholder="Password..." >

    <input  type="submit"   value="注册">   
</form>
</body>
 <script>
    document.getElementById("regedit").onsubmit=function(){
        let username=document.getElementById("username").value;
        let password=document.getElementById("password").value;
        let regexp1=/^[a-zA-Z_0-9]{4,16}$/;
        if(!regexp1.test(username)){
            alert("用户名不符合规则");
            return false;
    }
    let regexp2=/^[\d]{3,6}$/;
    if(!regexp2.test(password)){
            alert("请输入6位纯数字");
            return false;
    }

    return true;
}

</script> 
</html>